<template>
  <div class="xq">
    <p>设备编辑</p>

    <div class="ul">
      <p>设备编号：{{ bianji.id }}</p>
      <el-divider></el-divider>

      <el-form :model="form" :rules="rules">
        <el-form-item
          label="设备名称"
          prop="name"
          :label-width="formLabelWidth"
        >
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          label="设备分类"
          prop="category"
          :label-width="formLabelWidth"
        >
          <el-select v-model="form.category" placeholder="全部分类">
            <el-option
              v-for="item in lis"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="设备数量"
          prop="number"
          :label-width="formLabelWidth"
        >
          <el-input v-model="form.number" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item
          label="设备单价"
          prop="price"
          :label-width="formLabelWidth"
        >
          <el-input v-model="form.price" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item
          label="购置时间"
          prop="time"
          :label-width="formLabelWidth"
        >
          <div class="block">
            <el-date-picker
              v-model="form.time"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </div>
          <!-- <div class="block">
            <el-date-picker
              v-model="form.time"
              type="datetime"
              placeholder="选择日期时间"
            >
            </el-date-picker>
          </div> -->
        </el-form-item>
      </el-form>

      <el-button @click="handleClick" size="medium" type="success"
        >返回列表</el-button
      >
      <el-button @click="seave" size="medium" type="primary">保存</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "BianJi",
  props: ["bianji"],
  data() {
    return {
      dialogFormVisible: true,
      form: {
        id: "",
        name: "",
        number: "",
        category: "",
        price: "",
        time: "",
      },
      formLabelWidth: "100px",
      lis: [],
      rules: {
        name: [
          { required: true, message: "请输入名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        number: [
          { required: true, message: "请输入数量", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        price: [
          { required: true, message: "请输入价格", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        category: [
          { required: true, message: "请选择分类", trigger: "change" },
        ],
        time: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
      },
    };
  },
  methods: {
    //   返回列表，隐藏当前界面
    handleClick() {
      this.$bus.$emit("fhlb");
    },
    // 保存按钮
    async seave() {
      let res = await this.$axios({
        method: "POST",
        url: "/pre-edit",
        data: this.form,
      });
      console.log(res);
      this.$bus.$emit("fhlb", true);
    },
    // 分类列表
    async listss() {
      let res = await this.$axios({
        method: "get",
        url: "/category-list",
        data: this.todata,
      });

      this.lis = res.data.data;
    },
  },
  created() {
    let { status, ...form } = this.bianji;
    console.log(status);
    this.form = form;
  },
  mounted() {
    this.listss();
  },
};
</script>

<style lang="less" scoped>
p {
  font-size: 20px;
}
.xq {
  width: 100%;
  height: 100%;
  // background: rgb(100, 97, 97);
  padding: 30px;
}
span {
  width: 100px;
  height: 30px;
  display: inline-block;
  text-align: right;
  margin: 10px 20px;
}
.ul {
  width: 90%;
  padding: 30px 20px;
  background: rgb(165, 169, 173);
  border-radius: 20px;
  li {
    margin-top: 20px;
  }
  button {
    margin: 50px;
  }
}
</style>